<?php
Zend_Loader::loadClass('Application_Printer_Base');

/**
 * Printer per pChart
*/

include(APPLICATION_LIBRARY . "/pChart/class/pDraw.class.php");
include(APPLICATION_LIBRARY . "/pChart/class/pImage.class.php");
include(APPLICATION_LIBRARY . "/pChart/class/pData.class.php");

class Pchart extends Application_Printer_Base
{
	protected $_cartridge; 

	public function call() {

		/* Create your dataset object */
		$myData = new pData();
		
		/* Recupero dati (di comodo) da PlotData */
		$dataPoints = $this->_params->getSerie();
		$x = $this->_params->getXAxis();
		$y = $this->_params->getYAxis();
		// Setup asse X
		$valueX=array();
		if(count($x->values)==365){
			for($i=0; $i<365; $i++){
				$valueX[$i]=substr($x->values[$i],3,3);
			}	
		$myData->addPoints($valueX, "XAxis");
		} else $myData->addPoints($x->values, "XAxis");
		$myData->setAbscissa("XAxis");
		$myData->setAbscissaName($x->label);
		// Setup asse Y
		$myData->setAxisName(0, $y->label."[".$y->unit."]");
		// Setup serie dati
		$myData->addPoints($dataPoints->values, $dataPoints->label."[".$y->unit."]");
	
		
		/* Create a pChart object and associate your dataset */
		$myPicture = new pImage(800,300,$myData);
		//Creo la griglia ed il rettangolo nero per il grafico
		$myPicture->drawGradientArea(0,0,800,300,DIRECTION_VERTICAL,array("StartR"=>100,"StartG"=>100,"StartB"=>100,"EndR"=>50,"EndG"=>50,"End
				B"=>50,"Alpha"=>100));
		$myPicture->drawGradientArea(0,0,800,300,DIRECTION_HORIZONTAL,array("StartR"=>100,"StartG"=>100,"StartB"=>100,"EndR"=>50,"EndG"=>50,"EndB"=>50,
				"Alpha"=>100));
		/* Choose a nice font */
		$myPicture->setFontProperties(array("R"=>255,"G"=>255,"B"=>255,"FontName"=>APPLICATION_LIBRARY . "/pChart/fonts/tahoma.ttf","FontSize"=>10));
		/* Define the boundaries of the graph area */
		$myPicture->setGraphArea(100,40,750,250);
		
		//$scaleSettings = array("Mode"=>SCALE_MODE_MANUAL,"ManualScale"=>$axisBoundaries,"DrawSubTicks"=>TRUE);
	
		$myPicture->drawScale($this->_cartridge['scaleSettings']);
		//Disegno il grafico
		$myPicture->drawLineChart();
		
		
		//evidenzia i puntini nel grafico
		if (!empty($this->_cartridge['drawPlotChart']))
			$myPicture->drawPlotChart();
		
		//disegno la legenda del grafico
		//$myPicture->drawLegend(600,20,$myData->getData(),255,255,255);
		
		$myPicture->setFontProperties(array("FontName"=>APPLICATION_LIBRARY . "/pChart/fonts/tahoma.ttf","FontSize"=>10,"R"=>30,"G"=>30,"B"=>30));
		//$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
		$myPicture->drawLegend(500,20, array("Style"=>LEGEND_ROUND,"Mode"=>LEGEND_HORIZONTAL,
		"BoxWidth"=>30));
		
		/* Render the picture (choose the best way) */
		$myPicture->render(null);
	}
	
	public function loadCartridge($cartridge) {
		$cartridges = array(
			'auto-scale' => array(
					"scaleSettings" => array(
							"Mode" => SCALE_MODE_FLOATING,
							"DrawSubTicks" => false,
							"LabelingMethod" => LABELING_DIFFERENT
					),
					"drawPlotChart" => false
			),
			'scale-from-0' => array(
				"scaleSettings" => array(
					"Mode" => SCALE_MODE_START0,
					"DrawSubTicks" => true,
				),
				"drawPlotChart" => true
			),
			'blue' => array(
			)
		);
		$defaultCartridge = 'auto-scale';

		$this->_cartridge = array_key_exists($cartridge, $cartridges) ?
			$cartridges[$cartridge] : $cartridges[$defaultCartridge];
		
		
	}
}
